$.fn.extend({
	star : function(options, isLock) {
		var o = {
			se : 5,
			xiang : 5,
			wei : 5
		};
		$.extend(o, options);
		var $box = $(this);

		// width=135px;

		var calcScore = function() {
		};

		var $scoreStarBox = $('<div class="star-score" />');
		var $star = $('<div class="star-box"><b>美味度：</b><p>'
				+ ((o.se + o.xiang + o.wei) / 3).toFixed(1) + '</p><div class="star"><span style="width: 65px;"></span></div></div>');
		var createBar = function(type, score,name) {
		
			var barHtml = '<div class="bar-box"><b>'+name+'：</b><p>' + score + '</p><div class="score-bar">'
					+ '<table cellpadding="0" cellspacing="0" border="0">'
					+ '<tr><td class="bg-' + type + 'l"></td><td class="bg-'
					+ type + 'c"></td><td class="bg-' + type + 'r"></td></tr>'
					+ '</table></div></div>';
			return $(barHtml);
		};

		var $barOrange = createBar("r", o.se,"色");
		var $barRed = createBar("o", o.xiang,"香");
		var $barGreen = createBar("g", o.wei,"味");

		$scoreStarBox.append($star);
		$scoreStarBox.append($barOrange);
		$scoreStarBox.append($barRed);
		$scoreStarBox.append($barGreen);

		var barObj = {
			se : {
				obj : $barOrange,
				step : o.se,
				lock : false
			},
			xiang : {
				obj : $barRed,
				step : o.se,
				lock : false
			},
			wei : {
				obj : $barGreen,
				step : o.se,
				lock : false
			}
		};
		var changeWidth = function(id, step) {
			barObj[id]["obj"].find("td").eq(1).css("width", step * 14);
			
			barObj[id]["obj"].find("p").html(step);
			barObj[id]["step"] = step;

			var total = 0;
			var ave=0;
			$.each(barObj, function(id, $obj) {
						total += $obj["step"];
					})
			ave=(total / 3).toFixed(1);
			$star.find("p").html(ave);
			$star.find("span").css("width",Math.floor(ave*13));
		};
		if (!isLock) {

			var barWidth = 0;
			var step = 0;

			$.each(barObj, function(id, $obj) {
						$obj["obj"].find(".score-bar").mousemove(function(e) {
									if (!$obj["lock"]) {
										barWidth = e.pageX
												- $(this).offset().left;
										if (barWidth > 131) {
											barWidth = 131;
										}
										step = Math.ceil(barWidth / 14);
										if (step > 5) {
											step = 5;
										} else if (step == 0) {
											step = 1;
										}
										changeWidth(id, step);
									}
								}).mouseout(function() {
									if (!$obj["lock"]) {
										changeWidth(id, 5);
									}
								}).click(function() {
									$obj["lock"] = true;
								});

					});

		} else {
			$.each(barObj, function(id, $obj) {
						changeWidth(id, $obj["step"]);
					});
		}

		$box.html($scoreStarBox);

	}
});
//example:
//取值方式待沟通
$(function() {
			$("#starBox").star({
						se : 5,
						xiang : 5,
						wei : 5
					}, false);
			
		});